

#include "hitBox.h"
#include "renderer.h"
#include "input.h"
#include "skeletalActor.h"



HitBox::HitBox(){

    name="hitBox";
    collisionActor=NULL;
    currentLoc=0;

    drawType=DRAW_TEA;

    //Actor Menu
    menuType.push_back("12AssignButton");
    menuProp.push_back("NULL");
    menuIcon.push_back("icon_base");


    menuType.push_back("15PickWorldButton");
    menuProp.push_back("NULL");
    menuIcon.push_back("icon_character");

    boxLocations.push_back(Vector3f(1.53,5.11,1.37));
    boxLocations.push_back(Vector3f(-0.95,4.51,1.57));
    boxLocations.push_back(Vector3f(-2.34,6.21,1.37));
    boxLocations.push_back(Vector3f(-0.42,2.31,1.97));
    boxLocations.push_back(Vector3f(-2.52,4.5,0.24));
    boxLocations.push_back(Vector3f(0.08,5.9,0.86));

    registerProperties();
}

HitBox::~HitBox(){}

void HitBox::registerProperties(){

Actor::registerProperties();

createMemberID("COLLISIONACTOR",&collisionActor,this);
}

void HitBox::setup(){

Actor::setup();
}

void HitBox::trigger(Actor * other){

    if (other->isA("PickWorldButton")){
        collisionActor=input->worldTarget;
        cout << "set Collision Actor to:" << collisionActor->name << endl;
        }
    else{
        cout << "added new Location!" << endl;
        cout << location << endl;


        }
        //here we assign a new location - just like a keyframe or something...
}

void HitBox::update(double deltaTime){

    if (collisionActor && collisionActor->isA("SkeletalActor")){
        SkeletalActor* skel=dynamic_cast<SkeletalActor*>(collisionActor);

        for (uint i=0; i<skel->bones.size();i++){
            Actor* bone=skel->bones[i];
            Vector3f boneLoc=(renderer->inverseCameraMatrix * bone->baseMatrix ).getTranslation();
            Vector3f distance = boneLoc-location;
            if (distance.length()< 0.5){
              if ((uint)currentLoc<boxLocations.size())
                setLocation(boxLocations[currentLoc++]);
              else{
                currentLoc=0;
                setLocation(boxLocations[currentLoc]);
                }
            cout << "hit!" << endl;
            }
        }
    }

}


void HitBox::create(){renderer->addActor(this);}
